<template>
  <div class="success-container">
    <div class="decorative-strip"></div>
    <a-card class="success-card">
      <div v-if="loading" class="loading-state">
        <a-spin />
        <p>Loading payment status...</p>
      </div>
      <div class="success-header" v-else>
        <div class="success-icon" v-if="status == 2">
          <check-circle-outlined />
        </div>
        <div class="failed-icon" v-else>
          <ExclamationCircleOutlined />
        </div>
        <p class="subtitle">{{ status == 2 ? 'Payment Successful' : 'Payment Failed' }}</p>
      </div>

      <div class="info-section">
        <div class="info-row">
          <span class="label">Order Number：</span>
          <span class="value">{{ orderNo }}</span>
        </div>
        <a-divider dashed />

        <div class="info-row">
          <span class="label">Payment amount：</span>
          <span class="value highlight">{{ useCurrency.currentCurrency.unit }}{{ proxy.$ConvertPrice(amount) }}</span>
        </div>
        <a-divider dashed />

        <div class="info-row">
          <span class="label">Payment Time：</span>
          <span class="value"><DateFormatter :value="payTime" format="MM/DD/YYYY HH:mm:ss" fallback="No" /></span>
        </div>
      </div>

      <div class="action-btns">
        <a-button
            type="primary"
            class="black-btn"
            @click="viewOrder">
          View order details
        </a-button>
        <a-button
            class="ghost-btn"
            @click="goHome">
          Back to Home
        </a-button>
      </div>
    </a-card>
  </div>
</template>

<script setup>
import {ref, onMounted, getCurrentInstance} from 'vue';
import { useRouter } from 'vue-router';
import { CheckCircleOutlined,ExclamationCircleOutlined } from '@ant-design/icons-vue';
import {getOrderDetail} from "@/api/order.ts";
import {Local} from "@/utils/storage.ts";
import {useCurrencyStore} from '@/store/currency.ts'
import DateFormatter from "@/components/common/DateFormatter.vue";
import {message} from "ant-design-vue";

const { proxy } = getCurrentInstance();
const useCurrency = useCurrencyStore();
const router = useRouter();
const loading = ref(true);

// 订单数据
const orderNo = ref('');
const amount = ref(0);
const payTime = ref('');
const orderId = ref('');
const status = ref('');

// 模拟加载
onMounted(() => {
  
  setTimeout(() => {
    getOrderDetails()
    loading.value = false;
  }, 5000);
});

const getOrderDetails = async () => {
  const res = await getOrderDetail(Local.get('orderId'))
  if (res.code === 200) {
    orderNo.value = res.result.order_no
    amount.value = res.result.pay_price
    payTime.value = res.result.pay_time
    status.value = res.result.status
    orderId.value = res.result.id
  }else {
    message.error(res.msg || 'Failed to get order details')
  }
}

const viewOrder = () => {
  router.push('/user/orders');
};

const goHome = () => {
  router.push('/');
};
</script>

<style lang="scss" scoped>
.success-container {
  min-height: 100vh;
  background: linear-gradient(135deg, #f8f9fa 0%, #ffffff 100%);
  padding: 40px 20px;
  position: relative;

  .page-title {
    text-align: center;
    font-size: 36px;
    color: #333;
    margin-bottom: 40px;
  }

  .decorative-strip {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: 8px;
    background: repeating-linear-gradient(
            45deg,
            #000,
            #000 15px,
            transparent 15px,
            transparent 30px
    );
  }
}

.success-card {
  max-width: 680px;
  margin: 0 auto;
  border: 2px solid #000;
  border-radius: 12px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.08);

  :deep(.ant-card-body) {
    padding: 40px;
  }
}

.success-header {
  text-align: center;
  margin-bottom: 40px;

  .success-icon {
    font-size: 60px;
    color: #52c41a;
    animation: checkmark 0.6s ease;
  }

  .failed-icon {
    font-size: 60px;
    color: #d41818;
    animation: checkmark 0.6s ease;
  }

  .title {
    font-size: 32px;
    color: #333;
    margin: 20px 0 8px;
    font-weight: 500;
  }

  .subtitle {
    font-size: 16px;
    color: #666;
    letter-spacing: 2px;
  }
}

.loading-state {
  text-align: center;
  margin: 40px 0;
}

.info-section {
  margin: 30px 0;

  .info-row {
    display: flex;
    justify-content: space-between;
    padding: 18px 0;

    .label {
      color: #666;
      font-size: 16px;
    }

    .value {
      color: #333;
      font-weight: 500;

      &.highlight {
        font-size: 24px;
        letter-spacing: 1px;
      }
    }
  }
}

.action-btns {
  text-align: center;

  .black-btn {
    background: #000;
    border-color: #000;
    font-size: 16px;

    &:hover {
      background: #333;
    }
  }

  .ghost-btn {
    border-color: #000;
    color: #000;
    margin-left: 20px;

    &:hover {
      background: rgba(0,0,0,0.05);
    }
  }
}

@keyframes checkmark {
  0% { transform: scale(0); opacity: 0; }
  50% { transform: scale(1.2); }
  100% { transform: scale(1); opacity: 1; }
}
</style>
